<?php
	class InteretsProTypeManager{
		  private $_db;
	
		  public function __construct($db){
				$this->setDb($db);
		  }
		  
		  public function setDb(PDO $db){
				$this->_db = $db;
		  }
		  
		  public function add(InteretsProType $interetsprotype){// permet d'ajouter une question
				$q = $this->_db->prepare('INSERT INTO interetspro_type SET type = :type, idRefReponse = :idRefReponse');
				$q->bindValue(':type', $interetsprotype->type());
				$q->bindValue(':idRefReponse', $interetsprotype->idRefReponse());
				$q->execute();
		  }
		  
		  public function delete(InteretsProType $interetspro){// permet de supprimer une question
			  $this->_db->exec('DELETE FROM interetspro_type WHERE idRefReponse = '.$interetsprotype->idRefReponse().' AND type = '.$interetspro->type());
		  }
		  
		  public function update(InteretsProType $interetsprotype){// permet de modifier une question
				$q = $this->_db->prepare('UPDATE interetspro_type SET type = :type WHERE idRefReponse ='.$interetsprotype->idRefReponse());
				$q->bindValue(':type', $interetsprotype->type());
				$q->bindValue(':idRefReponse', $interetsprotype->idRefReponse());
				$q->execute();
		  }
		  
		  public function get($idRefReponse){// retourne l'objet d'id correspondant
				$q = $this->_db->query('SELECT * FROM interetspro_type WHERE idRefReponse = '.$idRefReponse);
				$donnees = $q->fetch();
				return new InteretsProType($donnees);
		  }
		  
		  public function getGroupByType(){// retourne l'objet d'id correspondant
				$interetsprotype = array();
				$q = $this->_db->query('SELECT * FROM interetspro_type GROUP BY type');
				while($donnees = $q->fetch())
				{
					$interetsprotype[] = new InteretsProType($donnees);
				}
				return $interetsprotype;
		  }
	}
?>